import React,{Component} from 'react';
import './companyfile.scss';
import { getIndexInfo, getRealCertInfo } from 'api/company.js';
import FileInfo from './companyFile/fileInfo.jsx';
import FileAuth from './companyFile/fileAuth.jsx';
export default class Componentfile extends Component{
	constructor (props) {
		super(props)
		this.state={
			companyFile: {},
			shop_info: {},
			title: ['基本信息', '认证信息'],
			current: 0,
			cont: <FileInfo shop_id={this.props.shop_id}/>
		}
	}
	show (index) {
		this.setState({
			current:index
		}, () => {
			if (this.state.current === 0) {
				this.setState({
					cont: <FileInfo shop_id={this.props.shop_id}/>
				})
			} else if (this.state.current === 1) {
				this.setState({
					cont: <FileAuth shop_id={this.props.shop_id}/>
				})
			}
		})
	}
	_getRealCertInfo () {
		getRealCertInfo({
			shop_id :this.props.shop_id
		}).then( res => {
			if (res.code === 1) {
				this.setState({
					companyFile:res.data
				})
			}
		})
	}
	_getIndexInfo () {
		getIndexInfo({
			shop_id : this.props.shop_id
		}).then(res => {
			if(res.code === 1){
				Object.keys(res.data).forEach(key => {
					if (key === 'shop_info '){
						this.setState({
							shop_info:res.data[key]
						})
					}
				})
			}
		})
	}
	componentDidMount () {
		// console.log(this.props.shop_id)
	}
	render(){
		return(
			<div>
				<div className="company_nav com_file">
					{
						this.state.title.map((item,index) => {
							return(
								<div className={this.state.current === index && 'active'} onClick={this.show.bind(this,index)} key={index}>{item}</div>
							)
						})
					}
				</div>
				<div className="company_content">
					<div className={this.state.type}>
						{this.state.cont}
					</div>
				</div>
			</div>
		)
	}
}